# mountall-shell - Recovery shell for filesystem failure
#
# If mountall exits to indicate that manual recovery is required, this
# starts the necessary shell.

description	"Recovery shell for filesystem failure"

start on stopped mountall EXIT_STATUS=[!5]
stop on runlevel [06]

task
console owner

script
    case "$EXIT_STATUS" in
    1)
	echo "General error mounting filesystems."
	;;
    2)
	echo "Filesystem check failed."
	;;
    3)
	echo "Mount of filesystem failed."
	;;
    4)
	echo "Mount of root filesystem failed."
	;;
    *)
	echo "Unknown error checking or mounting filesystems."
	;;
    esac

    echo "A maintenance shell will now be started."
    if [ "$EXIT_STATUS" = "4" ]
    then
	echo "CONTROL-D will terminate this shell and reboot the system."
    else
	echo "CONTROL-D will terminate this shell and re-try."
    fi

    /sbin/sulogin
end script

post-stop script
    if [ -z "$UPSTART_STOP_EVENTS" ]
    then
	if [ "$EXIT_STATUS" = "4" ]
	then
	    umount -a || :
	    exec reboot -f
	else
	    exec start --no-wait mountall
	fi
    fi
end script
